﻿using EASEater.Help;
using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Threading;

namespace EASEater
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        DispatcherTimer FilterTimer { get; set; }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var tab = tabs1.Items[tabs1.SelectedIndex] as TabItem;
            var grid = tab.Content as DataDicGrid;

            if (grid.TableSource != null) 
                return;

            switch (tabs1.SelectedIndex)
            {
                case 0:
                    grid.TableSource = Data.JoinOfficialTables;
                    grid.FieldSource = Data.JoinOfficialFields;
                    break;
                case 1:
                    new Task(() =>
                    {
                        Data.LoadOfficial();
                        this.Dispatcher.Invoke(() =>
                        {
                            grid.TableSource = Data.OfficialTables;
                            grid.FieldSource = Data.OfficialFields;
                        });
                    }).Start();
                    break;
                case 2:
                    break;
                case 3:
                    new Task(() =>
                    {
                        Data.LoadExcel();
                        this.Dispatcher.Invoke(() =>
                        {
                            grid.TableSource = Data.ExcelTables;
                            grid.FieldSource = Data.ExcelFields;
                        });
                    }).Start();
                    break;
            }
        }
    }
}


